<template>
	<view>
		<image class="bgimg" src="https://pt2.0.xianmxkj.com/file/uploadPath/2022/11/09/8030d98585b4864140a4c1da8d6fa306.png" mode="widthFix"></image>

		<view class="info">
			<view class="info-box">
				<view class="info-box-title">
					推广申请信息
				</view>
				
				<view class="info-box-item">
					<view class="info-box-item-name">联系人姓名</view>
					<u-input placeholder="请输入联系人姓名" v-model="applyName" :clearable="false"></u-input>
				</view>
				<view class="line"></view>
				<view class="info-box-item">
					<view class="info-box-item-name">联系人手机号</view>
					<u-input placeholder="请输入联系人手机号" v-model="applyPhone" :clearable="false"></u-input>
				</view>
				<view class="line"></view>
				<view class="info-box-item">
					<view class="info-box-item-name">地址</view>
					<u-input placeholder="请选择所在区域地址" v-model=" applyContent" @click="getcity()" :disabled="true"
						:clearable="false">
					</u-input>
				</view>
				<view class="" v-if="remarks && type!=2 && type!=1" style="color: red;">
					拒绝原因：{{remarks}}
				</view>
				<!-- <view class="sub-box-l" @click="submit()" v-if="applyId!=1">确认提交</view> -->
				<view class="sub-box-l" @click="submit()" v-if="type!=2 && type!=1">确认提交</view>
			</view>
		</view>
		<!-- <view class="sub">
			<view class="sub-box">
				<view class="sub-box-l" @click="submit()">确认提交</view>
				<view class="sub-box-r" @click="Changekefu()">直接联系 </view>
			</view>
		</view> -->


	</view>
</template>

<script>
	export default {
		data() {
			return {
				applyName: '',
				applyPhone: '',
				applyContent: '',
				applyId:'',
				type:'',//1：首次提交 2：已通过 3：已拒绝
				remarks:'',
			};
		},
		onLoad() {
			this.getDetail()
		},
		onShow() {

		},
		methods: {
			getcity() {
				// console.log(55555)
				let that = this
				uni.chooseLocation({
					success: function(res) {
						console.log('位置名称：' + res.name);
						console.log('详细地址：' + res.address);
						console.log('纬度：' + res.latitude);
						console.log('经度：' + res.longitude);
						that.applyContent = res.address + res.name
					}
				});
			},
			Changekefu() {
				let that = this
				// #ifdef MP-WEIXIN
				wx.openCustomerServiceChat({
					extInfo: {
						url: that.$queue.getData('kefu')
					},
					corpId: that.$queue.getData('kefuAppId'),
					success(res) {}
				})
				// #endif
				// #ifdef H5
				window.location.href = that.$queue.getData('kefu');
				// #endif
				// #ifdef APP
				let kefu = that.$queue.getData('kefu')
				console.log(kefu)
				plus.runtime.openURL(kefu, function(res) {});
				// #endif
			},
			getDetail() {
				this.$Request.getT("/app/userExtension/getUserExtensionInfo").then(res => {
					if (res.code == 0&&res.data) {
						this.applyName=res.data.realName
						this.applyPhone=res.data.phone
						this.applyContent=res.data.addressDetail
						this.applyId = res.data.extensionId
						this.type=res.data.status
						this.remarks = res.data.remarks
					}else{
						this.type=''
					}
				})
			},
			submit() {
				if (!this.applyName) {
					uni.showToast({
						title: '请输入联系人姓名',
						icon: 'none'
					})
					return
				}
				if (!this.applyPhone) {
					uni.showToast({
						title: '请输入联系人手机号码',
						icon: 'none'
					})
					return
				}
				if (!this.applyContent) {
					uni.showToast({
						title: '请输入地址',
						icon: 'none'
					})
					return
				}
				let data = {
					realName: this.applyName,
					phone: this.applyPhone,
					addressDetail: this.applyContent,
				}
				if(this.applyId){
					data.extensionId = this.applyId
				}
				if(this.type==''){
					this.$Request.postT("/app/userExtension/addUserExtension", data).then(res => {
						if (res.code == 0) {
							uni.showToast({
								title: '提交成功！',
								icon: 'none'
							})
							setTimeout(function() {
								uni.navigateBack()
							}, 1000)
						}
					})
				}else if(this.type==3){
					this.$Request.postT("/app/userExtension/updateUserExtension", data).then(res => {
						if (res.code == 0) {
							uni.showToast({
								title: '修改成功！',
								icon: 'none'
							})
							setTimeout(function() {
								uni.navigateBack()
							}, 1000)
						}
					})
				}
				
			}
		}
	}
</script>

<style lang="less">
	page {
		background-color: #f5f5f5;
	}

	.bgimg {
		position: relative;
		width: 100%;
	}

	.info {
		width: 680upx;
		height: auto;
		display: flex;
		justify-content: center;
		position: absolute;
		top: 700rpx;
		// background-image: url('../static/zsbg.png');
		background: linear-gradient(0deg, #3A88FF 0%, #B7E1FF 100%);
		border-radius: 32upx;
		background-size: 100% 100%;
		margin: 30upx;
		padding: 30upx;

		.info-box {
			width: 620rpx;
			background: #ffffff;
			border-radius: 32upx;
			padding: 30upx;

			.info-box-title {
				color: #333333;
				font-size: 32rpx;
				font-weight: 800;
				text-align: center;
			}

			.info-box-item {
				margin-top: 30rpx;

				.info-box-item-name {
					font-size: 28rpx;
					color: #333333;
					font-weight: 800;
					margin-bottom: 10rpx;
				}
			}

			.line {
				width: 100%;
				border: 1rpx solid #EAEAEA;
				margin-top: 20rpx;
			}
		}
	}

	.sub-box-l {
		// width: 290rpx;
		height: 88rpx;
		background: #435DF0;
		border-radius: 44rpx;
		color: #ffffff;
		font-size: 28rpx;
		font-weight: bold;
		display: flex;
		justify-content: center;
		align-items: center;
		margin-top: 60upx;
	}

	.sub {
		width: 100%;
		height: 88rpx;
		display: flex;
		justify-content: center;
		position: absolute;
		top: 1430rpx;

		.sub-box {
			width: 613rpx;
			height: 100%;
			display: flex;
			justify-content: space-between;

			.sub-box-l {
				width: 290rpx;
				height: 88rpx;
				background: #97A8F8;
				border-radius: 44rpx;
				color: #ffffff;
				font-size: 28rpx;
				font-weight: bold;
				display: flex;
				justify-content: center;
				align-items: center;
			}

			.sub-box-r {
				width: 290rpx;
				height: 88rpx;
				background: #435DF0;
				border-radius: 44rpx;
				color: #ffffff;
				font-size: 28rpx;
				font-weight: bold;
				display: flex;
				justify-content: center;
				align-items: center;
			}
		}
	}
</style>
